﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace MC.RideEvent.Mvc.Models.ViewModel
{
    public enum Sexe
    {
        Homme, Femme    
    }

    public class MemberViewModel
    {
        public int Id { get; set; }
        public string Code { get; set; }

        [Required(ErrorMessage="*")]
        [Display(Name="Nom")]
        [StringLength(50)]
        public string Name { get; set; }

        [Required(ErrorMessage="*")]
        [StringLength(50)]
        [Display(Name = "Prénom")]
        public string FirstName { get; set; }

        [Required(ErrorMessage = "*")]
        [Display(Name = "Email")]
        [RegularExpression(@"^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$", ErrorMessage = "email invalide")]
        public string Email { get; set; }

        [Required(ErrorMessage="*")]
        [DataType(DataType.Date)]
        [Display(Name = "Date de Naissance")]
        public DateTime Birthday { get; set; }

        [Required(ErrorMessage="*")]
        [StringLength(120)]
        [Display(Name = "Adresse")]
        public string Address { get; set; }

        [Required(ErrorMessage="*")]
        [StringLength(80)]
        [Display(Name = "Ville")]
        public string City { get; set; }

        [Required(ErrorMessage="*")]
        [StringLength(5)]
        [Display(Name = "Code Postal")]
        public string Cp { get; set; }

        [Required(ErrorMessage="*")]
        [StringLength(1)]
        [Display(Name = "Sexe")]
        public string Sexe { get; set; }

        [Required(ErrorMessage = "*")]
        [StringLength(8)]
        [DataType(DataType.Password)]
        [Display(Name = "Mot de passe")]
        public string Password { get; set; }

        [Required(ErrorMessage = "Confirmation du mot de passe obligatoire")]
        [StringLength(255, ErrorMessage = "Doit etre compris entre 5 et 8 caracteres", MinimumLength = 5)]
        [DataType(DataType.Password)]
        [Compare("Password")]
        public string ConfirmPassword { get; set; }

        [DataType(DataType.Date)]
        [Display(Name = "Date d'obtention du permis de conduire")]
        public DateTime? DriveLicenceDate { get; set; }

        public string DriveLicenseDateString()
        {
            var date = DriveLicenceDate != null ? (Convert.ToDateTime(DriveLicenceDate)).ToString("dd MMM yyyy") : string.Empty;

            return date;
        }

        public string FullName()
        {
            var fn = string.Format("{0} {1}", Name, FirstName);

            return fn;
        }

        #region Dependency properties

        [ScaffoldColumn(false)]
        public List<VehiculeViewModel> Vehicules { get; set; }

        [ScaffoldColumn(false)]
        public List<CarModel> Cars { get; set; }
        #endregion
    }
}